#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>

int num=50;
sem_t mysem1;
sem_t mysem2;



void *myfunc1(void *arg)
{
	while(1)	
	{
		sem_wait(&mysem1);
		printf("+++++++thread 1 :%d\n",num++);
		sleep(1);
		sem_post(&mysem2);
	}
}

void *myfunc2(void *arg)
{
	while(1)
	{
		sem_wait(&mysem2);
		printf("thread 2 :%d\n",num++);
		sleep(1);
		sem_post(&mysem1);
	}
}


int main(int argc, const char *argv[])
{
sem_init(&mysem1,0,1);
sem_init(&mysem2,0,0);

	pthread_t tid1;
	pthread_t tid2;

	pthread_create(&tid1,NULL,myfunc1,NULL);
	pthread_create(&tid2,NULL,myfunc2,NULL);
	
	pthread_detach(tid1);
	pthread_detach(tid2);
	
	while(1);

	return 0;
}
